import 'package:fl_amap/fl_amap.dart';
import '/util/logger_util.dart';
import '/util/toast_util.dart';

/// <summary>
/// author：zwb
/// dateTime： 2021/12/20 15:02
/// filePath： lib/util/fl_amap_util.dart
/// desc: 高德定位工具类
/// <summary>
///
class FlAmapUtil {

  /// 初始化AMap
  static initialize() async => await FlAMapLocation().initialize(
      AMapLocationOption()).then((value) => logger("初始化AMap${value ? '成功' : '失败'}",tag: '高德'),
  );

  /// 获取定位信息
  static Future<AMapLocation?> getLocation() async {
    /// 务必先初始化 并获取权限
    AMapLocation? location = await FlAMapLocation().getLocation(true);
    if(location!.code == 12) toast("当前缺少位置权限，当前无法获取位置");
    return location;
  }

  /// 销毁
  static dispose() => FlAMapLocation().dispose();
}
